'use strict';
/**
 * Created by henian.xu on 2018/11/5.
 *
 */

const path = require('path');

module.exports = {
    /**
     * generator nuxt conifg
     * @param {object|string} config  uninital nuxt config
     * @return {object} inital nuxt config
     */
    loadNuxtConfig(config) {
        let options = config.nuxt;
        try {
            if (typeof options === 'string') {
                options = require(options);
            }
        } catch (e) {
            console.warn('[egg-nuxt] ' + options + ' nuxt config file is not exists');

            options = {
                srcDir: path.join(config.baseDir, './resources'),
                rootDir: config.baseDir,
            };
            console.warn('[egg-nuxt] default options:', JSON.stringify(options));
        }
        // Create development build when calling `egg-bin dev`
        options.dev = config.env === 'local';
        return options;
    },
};
